package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.entity.DeviceData;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "管理端 - 物联网iot相关接口")
@RestController
@RequestMapping("/iot")
public class DeviceController {

  @Autowired
  private DeviceService deviceService;

     @ApiOperation(value = "从物联网平台同步产品列表")
     @PostMapping("/syncProductList")
     public ResponseResult syncProductList() {
         deviceService.syncProductList();
          return ResponseResult.success();
     }

    @ApiOperation(value = "查询所有产品列表")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> list=deviceService.allProduct();
        return ResponseResult.success(list);
    }

    @ApiOperation(value = "注册设备")
    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto  deviceDto) {
           deviceService.registerDevice(deviceDto);
           return ResponseResult.success();
    }

    @ApiOperation(value = "分页查询设备列表")
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        PageResponse<DeviceVo> pageResponse= deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }
    @ApiOperation(value = "查询设备详细数据")
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult queryDeviceDetail(@RequestBody QueryDeviceDetailRequest queryDeviceDetailRequest) {
       DeviceVo  deviceVo= deviceService.queryDeviceDetail(queryDeviceDetailRequest);
        return ResponseResult.success(deviceVo);
    }
    //删除设备
    @ApiOperation(value = "删除设备")
    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest deleteDeviceRequest) {
        deviceService.deleteDevice(deleteDeviceRequest);
        return ResponseResult.success();
    }



    //查看指定产品的已发布物模型中的功能定义详情
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest queryDeviceDetailRequest) {
        ResponseResult responseResult=deviceService.queryThingModelPublished(queryDeviceDetailRequest);
        return  responseResult;
    }

    //查看指定产品的已发布物模型中的功能定义详情
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest queryDeviceDetailRequest) {
        ResponseResult responseResult=deviceService.queryDevicePropertyStatus(queryDeviceDetailRequest);
        return  responseResult;
    }

    //修改设备备注名称
    @ApiOperation(value = "修改设备备注名称")
    @PostMapping("/UpdateDevice")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto) {
         deviceService.updateDevice(deviceDto);
        return  ResponseResult.success();
    }





}
